package com.chuisha;

import org.slf4j.MDC;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
//线程池 增加 mdc trace 传递
public class TraceThreadPoolTaskExceutor extends ThreadPoolTaskExecutor {

    public TraceThreadPoolTaskExceutor() {
        super();
    }

    @Override
    public void execute(Runnable tack) {
        super.execute(ThreadMDCUtil.wrap(tack, MDC.getCopyOfContextMap()));
    }

    @Override
    public void execute(Runnable task, long startTimeout) {
        super.execute(ThreadMDCUtil.wrap(task, MDC.getCopyOfContextMap()), startTimeout);
    }

    @Override
    public Future<?> submit(Runnable task) {
        return super.submit(ThreadMDCUtil.wrap(task, MDC.getCopyOfContextMap()));
    }

    @Override
    public <T> Future<T> submit(Callable<T> task) {
        return super.submit(ThreadMDCUtil.wrap(task, MDC.getCopyOfContextMap()));
    }
}
